package com.tongji.diy.model.furniturePlacementOptimization.assembleComplement
{
	public class FacalCompound extends Facal
	{
		private var _container:FacalContainer;
		private var _containee:FacalContainee;
		
		public function FacalCompound(container:FacalContainer, containee:FacalContainee,furnitrueIndex:int = -1, furnitureClass:int = -1,length:Number = 0, width:Number = 0, height:Number = 0, correspondingNumVector:Vector.<int> = null, SLpriorList:Vector.<SLbase> = null, visibleOrientation:Vector.<Boolean> = null, visibleDistance:Vector.<Number> = null)
		{
			_container = container;
			_containee = containee;
			super(furnitrueIndex, furnitureClass, setAganistWall(), setLength(), setWidth(), setHeight(), setCorrespondingNumVector(), setSLpriorList(),setVisibleOrientationList(),setVisibleDistanceList());
			setContaineeHeight();
		}
		
		private function setContaineeHeight():void
		{
			containee.z = container.height;
		}
		
		private function setAganistWall():Boolean
		{
			return _containee.anganistWall && _container.anganistWall;
		}
		
		private function setCorrespondingNumVector():Vector.<int>
		{
			var v:Vector.<int> = new Vector.<int>;
			for(var i:int = 0; i < containee.correspondingNumVector.length; i++)
				v.push(Math.min(_containee.correspondingNumVector[i], _container.correspondingNumVector[i]));
			
			return v;		
		}
		
		private function setLength():Number
		{
			return Math.max(_containee.length, _container.length);
		}
		
		private function setWidth():Number
		{
			return Math.max(_containee.width, _container.width);
		}
		
		private function setHeight():Number
		{
			return _containee.height + _container.height;
		}
		
		
		private function setVisibleOrientationList():Vector.<Boolean>
		{
			var v:Vector.<Boolean> = new Vector.<Boolean>;
			for(var i: int = 0; i < _containee.visibleOrientation.length; i++)
				v.push(_containee.visibleOrientation[i] && _container.visibleOrientation[i]);
			return v;
		}
		
		private function setVisibleDistanceList():Vector.<Number>
		{
			var v:Vector.<Number> = new Vector.<Number>;
			for(var i: int = 0; i < _containee.visibleOrientation.length; i++)
				v.push(Math.max(_containee.visibleDistance[i],  _container.visibleDistance[i]));
			return v;
		}
		
		private function setSLpriorList():Vector.<SLbase>
		{
			return _containee.SLlist;
		}
		
		public function get container():FacalContainer
		{
			return _container;
		}
		
		public function get containee():FacalContainee
		{
			return _containee;
		}
		
		public override function set x(x:Number):void
		{
			super.x = x;
			_container.x = x;
			_containee.x = x;
		}
		
		public override function set y(y:Number):void
		{
			super.y = y;
			_container.y = y;
			_containee.y = y;
		}
		
		public override function set angle(angle:Number):void
		{
			super.angle = angle;
			_container.angle = angle;
			_containee.angle = angle;
		}
	}
}